package com.grifo.database;

import javax.persistence.EntityManager;
import javax.persistence.LockModeType;
import javax.persistence.PersistenceContext;

public class JpaDao {

	@PersistenceContext
	private EntityManager em;

	public <T> T persist(T obj) {
		em.persist(obj);
		return obj;
	}

	public <T> T refresh(T obj) {
		em.refresh(obj);
		return obj;
	}

	public <T> T refresh(T obj, LockModeType lockModeType) {
		em.refresh(obj, lockModeType);
		return obj;
	}

	public void remove(Object obj) {
		em.remove(em.merge(obj));
	}

	public <T> void removeById(Class<T> clazz, Object id) {
		em.remove(em.find(clazz, id));
	}

}
